<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\Auction\ApplyCertificationRequest;
use App\Library\Requests\Auction\AuctionAddRequest;
use App\Library\Requests\Auction\AuctionAssignBidRequest;
use App\Library\Requests\Auction\AuctionBidRequest;
use App\Library\Requests\Auction\AuctionCertificationEditRequest;
use App\Library\Requests\Auction\AuctionEditRequest;
use App\Library\Requests\Auction\AuctionPageRequest;
use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Service\AuctionService;
use Illuminate\Http\JsonResponse;

class AuctionController extends BaseController
{
    /**
     * @param AuctionService $service
     */
    public function __construct(AuctionService $service)
    {
        $this->service = $service;
    }

    /**
     * 分页
     * @param AuctionPageRequest $request
     * @return JsonResponse
     */
    public function paging(AuctionPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    /**
     * 添加
     * @param AuctionAddRequest $request
     * @return JsonResponse
     */
    public function add(AuctionAddRequest $request): JsonResponse
    {
        return $this->service->add($request);
    }

    /**
     * 编辑
     * @param AuctionEditRequest $request
     * @return JsonResponse
     */
    public function edit(AuctionEditRequest $request): JsonResponse
    {
        return $this->service->edit($request);
    }
    /**
     * 举报
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function report(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->report($request);
    }

    /**
     * 上下架
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function editStatus(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->editStatus($request);
    }

    /**
     * 详情
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function detail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->detail($request);
    }

    /**
     * 删除
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function delete(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->delete($request);
    }

    /**
     * 出价
     * @param AuctionBidRequest $request
     * @return JsonResponse
     */
    public function bid(AuctionBidRequest $request): JsonResponse
    {
        return Lock::get($request->serialNumber . 'auction', function () use ($request) {
            return $this->service->bid($request);
        });
    }

    /**
     * bidRecord
     * @param BasePageRequest $request
     * @return JsonResponse
     */
    public function bidRecord(BasePageRequest $request): JsonResponse
    {
        return $this->service->bidRecord($request);
    }

    /**
     * checkBail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function checkBail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->checkBail($request);
    }

    /**
     * applyCertification
     * @param ApplyCertificationRequest $request
     * @return JsonResponse
     */
    public function applyCertification(ApplyCertificationRequest $request): JsonResponse
    {
        return Lock::get(USERID . __CLASS__ . __FUNCTION__, function () use ($request) {
            return $this->service->applyCertification($request);
        });
    }

    /**
     * followOrCancel
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function followOrCancel(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(USERID . __CLASS__ . __FUNCTION__, function () use ($request) {
            return $this->service->followOrCancel($request);
        });
    }

    /**
     * certificationEdit
     * @param AuctionCertificationEditRequest $request
     * @return JsonResponse
     */
    public function certificationEdit(AuctionCertificationEditRequest $request): JsonResponse
    {
        return Lock::get(USERID . __CLASS__ . __FUNCTION__, function () use ($request) {
            return $this->service->certificationEdit($request);
        });
    }

    /**
     * publishCertification
     * @return JsonResponse
     */
    public function publishCertification(): JsonResponse
    {
        return $this->service->publishCertification();
    }

    /**
     * numTj
     * @return JsonResponse
     */
    public function numTj(): JsonResponse
    {
        return $this->service->numTj();
    }

    /**
     * followPaging
     * @param BasePageRequest $request
     * @return JsonResponse
     */
    public function followPaging(BasePageRequest $request): JsonResponse
    {
        return $this->service->followPaging($request);
    }

    /**
     * 一口价购买
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function buy(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get($request->serialNumber . 'auction', function () use ($request) {
            return $this->service->buy($request);
        });
    }

    /**
     * 指定价格出价
     * @param AuctionAssignBidRequest $request
     * @return JsonResponse
     */
    public function assign(AuctionAssignBidRequest $request): JsonResponse
    {
        return Lock::get($request->serialNumber . 'auction', function () use ($request) {
            return $this->service->assign($request);
        });
    }

    /**
     * 复制
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function copy(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->copy($request);
    }
}
